Database Object, Databases Collection Example

This example creates a new Database object and opens an existing Database object in the default Workspace object. Then it enumerates the Database collection and the Properties collection of each Database object. See the methods and properties listed in the Database summary topic for additional examples.

Sub DatabaseObjectX()

   Dim wrkJet As Workspace
   Dim dbsNorthwind As Database
   Dim dbsNew As Database
   Dim dbsLoop As Database
   Dim prpLoop As Property

   Set wrkJet = CreateWorkspace("JetWorkspace", "admin", _
      "", dbUseJet)

   ' Make sure there isn't already a file with the name of
   ' the new database.
   If Dir("NewDB.mdb") <> "" Then Kill "NewDB.mdb"

   ' Create a new database with the specified
   ' collating order.
   Set dbsNew = wrkJet.CreateDatabase("NewDB.mdb", _
      dbLangGeneral)
   Set dbsNorthwind = wrkJet.OpenDatabase("Northwind.mdb")

   ' Enumerate the Databases collection.
   For Each dbsLoop In wrkJet.Databases
      With dbsLoop
         Debug.Print "Properties of " & .Name
         ' Enumerate the Properties collection of each
         ' Database object.
         For Each prpLoop In .Properties
            If prpLoop <> "" Then Debug.Print "  " & _
               prpLoop.Name & " = " & prpLoop
         Next prpLoop
      End With
   Next dbsLoop

   dbsNew.Close
   dbsNorthwind.Close
   wrkJet.Close

End Sub